package com.xh.cdp.sys.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xh.cdp.common.EasyUIPageModel;
import com.xh.cdp.sys.dao.SysUserDao;
import com.xh.cdp.sys.dao.SysUserRoleDao;
import com.xh.cdp.sys.entity.SysUserEntity;
import com.xh.cdp.sys.service.SysUserService;

@Service
public class SysUserServiceImpl implements SysUserService {

	@Autowired
	private SysUserDao sysUserDao;

	@Autowired
	private SysUserRoleDao sysUserRoleDao;

	@Override
	public SysUserEntity login(String loginCode, String loginPassword) {
		return sysUserDao.login(loginCode, loginPassword);
	}

	@Override
	public EasyUIPageModel<SysUserEntity> listUser(String sort, String order, int page, int rows) {
		return sysUserDao.listUser(sort, order, page, rows);
	}

	@Override
	public String addUser(SysUserEntity user) {
		String id = sysUserDao.addUser(user);
		sysUserRoleDao.addUserRole(id, user.getRoleId());
		return id;
	}

	@Override
	public SysUserEntity showUserInfo(String id) {
		return sysUserDao.showUserInfo(id);
	}

	@Override
	public String updateUser(SysUserEntity user) {
		sysUserRoleDao.updateUserRole(user);
		return sysUserDao.updateUser(user);
	}

	@Override
	public Integer deleteUser(String ids) {
		return sysUserDao.deleteUser(ids);
	}

	@Override
	public EasyUIPageModel<SysUserEntity> listUserBySearch(String sort, String order, int page, int rows,
			String searchName, String roleId, Integer state) {
		return sysUserDao.listUserBySearch(sort, order, page, rows, searchName, roleId, state);
	}

	@Override
	public Integer updateUserState(SysUserEntity user) {
		return sysUserDao.updateUserState(user);
	}

	@Override
	public String equalPassword(String password, String id) {
		return sysUserDao.equalPassword(password, id);
	}

	@Override
	public void updatePassword(String newPassword, String id) {
		sysUserDao.updatePassword(newPassword, id);
	}
}
